package com.jarvis.zeng.design.pattern.filter.demo;

import java.util.Iterator;
import java.util.List;

/**
 * @author ZengJun
 */
public class OrCritiria implements Criteria {
    private Criteria criteria1;
    private Criteria criteria2;
    public OrCritiria(Criteria criteria1, Criteria criteria2){
        this.criteria1 = criteria1;
        this.criteria2 = criteria2;
    }

    public List<Person> meetCriteria(List<Person> personList) {
        List<Person> personList1 = this.criteria1.meetCriteria(personList);
        List<Person> personList2 = this.criteria2.meetCriteria(personList);
        Iterator<Person> iterator = personList1.iterator();
        while(iterator.hasNext()){
            if(!personList2.contains(iterator.next())){
                personList2.add(iterator.next());
            }
        }
        return personList2;
    }
}
